/**
 * table 操作项混入
 * */

import { mapMutations } from 'vuex'
import { ApiRequest } from '@api/basePage'
export default {
    props: {
        rowData: {
            type: Object
        },
        indexData: {
            type: Number
        },
        basePath: {
            type: String
        },
        // 请求接口
        requestApi: {
            type: Object
        }
    },
    data () {
        return {
            row: {},
            index: '',
            jumpPath: ''
        }
    },
    watch: {
        rowData: function (n, o) {
            this.row = n
        },
        indexData: function (n, o) {
            this.index = n
        },
        basePath: function (n, o) {
            this.jumpPath = n
        }
    },
    created () {
        this.row = this.rowData
        this.index = this.indexData
        this.jumpPath = this.basePath
    },
    methods: {
        ...mapMutations('admin/baseList', ['setTableRowData']),
        // table 操作列点击事
        //  操作更多选择
        handleClickMore (name, row) {
            if (name === 'Delete') {
                this.$Modal.confirm({
                    title: '删除操作',
                    content: '确定删除此数据吗？',
                    onOk: () => {
                        let data = {
                            uuid: row.uuid
                        }
                        // 开始请求商品列表
                        ApiRequest(
                            this.requestApi.delTableList.url,
                            this.requestApi.delTableList.type,
                            data, true
                        ).then(res => {
                            this.$Message.success('删除成功')
                            this.actionsChange()
                        })
                    }
                })
            } else {
                let obj = {} // 动作的对象信息
                row.actions.forEach(item => {
                    if (name === item.name) {
                        obj = item
                        return false
                    }
                })
                this.setTableRowData(row)
                if (obj.handleType === 'link') {
                    // 操作类型为链接时，拼接参数跳转
                    let jumpPath = this.jumpPath + obj.name
                    let queryObj = {};
                    if (obj.params && obj.params.length > 0) {
                        obj.params.forEach(item => {
                            queryObj[item] = row[item]
                        });
                    } else {
                        queryObj = { 'uuid': row.uuid }
                    }

                    this.$router.push({ path: jumpPath, query: queryObj })
                } else {
                    // 操作类型为弹窗时 打开弹窗
                }
            }
        },
        // 父级重新请求接口
        actionsChange () {
            this.$emit('actionsChange')
        }
    }
}
